using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_CTDonHangList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        try
        {
            
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbDonHang donHang = tbDonHangBUS.GetByID(id);
            lit_MaDonHang.Text = donHang.IdDH .ToString();

            tbKhachHang khachHang = tbKhachHangBUS.GetByID(donHang.IdDH);
            lit_KhachHang.Text = khachHang.HoTen;
            lit_NgayDatHang.Text = donHang.NgayDatHang.ToString();
            lit_NgayGiaoHang.Text = donHang.NgayGiaoHang.ToString();
            lit_TriGia.Text = donHang.TriGia.ToString();
            tbTrangThaiDH trangthaiDH = tbTrangThaiDHBUS.GetById(int.Parse(donHang.IdTrangThaiDH.ToString()));
            cb_DaGiao.Checked = trangthaiDH .TrangThai_DH ;
            lit_DiaChiNhanHang.Text = donHang.DiaChiNhanHang;

            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbCTDonHangColumns.IdDH, Condition.EQUAL, donHang.IdDH);
           
            tbCTDonHangCollection cTDonHangCollection =
                tbCTDonHangBUS.Get(cri.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
                tbCTDonHangColumns.IdCTDonHang .ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = cTDonHangCollection;
            Repeater1.DataBind();

            PagerV2_8_1.ItemCount = total;
            if (PagerV2_8_1.ItemCount <= PagerV2_8_1.PageSize)
                PagerV2_8_1.Visible = false;
            else
                PagerV2_8_1.Visible = true;
        }
        catch
        {
            Response.Redirect("~/Admin/DonHangList.aspx");
        }
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbCTDonHang cTDonHang = (tbCTDonHang)e.Item.DataItem;
            tbSanPham  sanPham = tbSanPhamBUS .GetId (cTDonHang.IdSanPham );
            if (sanPham != null)
            {
                Literal lit_TenSP = (Literal)e.Item.FindControl("lit_TenSP");
                lit_TenSP.Text = sanPham .TenSP ;
            }
            Literal lit_ThanhTien = (Literal)e.Item.FindControl("lit_ThanhTien");
            int tongTien = cTDonHang.SoLuong  * cTDonHang.DonGia;
            lit_ThanhTien.Text = tongTien.ToString();
        }
    }
}
